package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToMapConverter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * 会员注册资料配置表 ms_mc_member_config
 * @author 万宁
 * @date 2020-05-29
 * @version 2.0.0
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_config", indexes = {@Index(name = "ms_mc_member_config_name_idx", columnList = "fieldLocalName"), @Index(name = "ms_mc_member_config_status_idx", columnList = "fieldStatus")})
public class MemberConfigDO  implements Serializable {

    private static final long serialVersionUID = 8490733395609054520L;

    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_config_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_config_seq", name="member_config_seq",allocationSize = 1)
    private Long id;

    /**
     * 字段名称
     */
    @Column(columnDefinition = "varchar(26)", nullable = false)
    private String fieldName;

    /**
     * 中文名称
     */
    @Column(columnDefinition = "varchar(30)")
    private String fieldLocalName;

    /**
     * 字段类型
     */
    @Column(columnDefinition = "varchar(20)", nullable = false)
    private String fieldType;

    /**
     * 字段类型附加属性
     */
    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition = "jsonb")
    private Map<String, Object> attr;

    /**
     * 字段长度
     */
    @Column(columnDefinition = "int4", nullable = false)
    private Integer fieldLength;

    /**
     * 是否允许为空
     */
    @Column(columnDefinition = "int2", nullable = false)
    private Integer fieldEmpty;

    /**
     * 分组名称
     */
    @Column(columnDefinition = "varchar(30)")
    private String groupName;

    /**
     * 排序
     */
    @Column(columnDefinition = "int4", nullable = false)
    private Integer fieldOrder;

    /**
     * 帮助信息
     */
    @Column(columnDefinition = "varchar(128)")
    private String fieldRemark;

    /**
     * 状态 0-停用 1-启用
     */
    @Column(columnDefinition = "int2", nullable = false)
    private Integer fieldStatus;

    /**
     * 标签枚举，定义在MemberConfigTagEnum中，如不是标签字段为0
     */
    @Column(columnDefinition = "int")
    private Integer tagEnum;

    /**
     * 标签名称，定义在 MemberConfigTagEnum 中，如不是标签字段为空字符串
     */
    @Column(columnDefinition = "varchar(50)")
    private String tagName;

    /**
     * 变更是否需要审核
     */
    @Column
    private Integer validate;

    /**
     * 校验规则枚举，定义在MemberConfigCheckRuleEnum中
     */
    @Column
    private Integer ruleEnum;

    /**
     * 一对多单向关联下拉框枚举值
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "memberConfig", cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private Set<MemberConfigLabelDO> labels;

    /**
     * 多对多双向关联角色
     */
    @JsonBackReference
    @ManyToMany(mappedBy = "configs", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    private Set<RoleDO> roles;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldLocalName() {
        return fieldLocalName;
    }

    public void setFieldLocalName(String fieldLocalName) {
        this.fieldLocalName = fieldLocalName;
    }

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public Map<String, Object> getAttr() {
        return attr;
    }

    public void setAttr(Map<String, Object> attr) {
        this.attr = attr;
    }

    public Integer getFieldLength() {
        return fieldLength;
    }

    public void setFieldLength(Integer fieldLength) {
        this.fieldLength = fieldLength;
    }

    public Integer getFieldEmpty() {
        return fieldEmpty;
    }

    public void setFieldEmpty(Integer fieldEmpty) {
        this.fieldEmpty = fieldEmpty;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public Integer getFieldOrder() {
        return fieldOrder;
    }

    public void setFieldOrder(Integer fieldOrder) {
        this.fieldOrder = fieldOrder;
    }

    public String getFieldRemark() {
        return fieldRemark;
    }

    public void setFieldRemark(String fieldRemark) {
        this.fieldRemark = fieldRemark;
    }

    public Integer getFieldStatus() {
        return fieldStatus;
    }

    public void setFieldStatus(Integer fieldStatus) {
        this.fieldStatus = fieldStatus;
    }

    public Integer getTagEnum() {
        return tagEnum;
    }

    public void setTagEnum(Integer tagEnum) {
        this.tagEnum = tagEnum;
    }

    public String getTagName() {
        return tagName;
    }

    public void setTagName(String tagName) {
        this.tagName = tagName;
    }

    public Integer getValidate() {
        return validate;
    }

    public void setValidate(Integer validate) {
        this.validate = validate;
    }

    public Integer getRuleEnum() {
        return ruleEnum;
    }

    public void setRuleEnum(Integer ruleEnum) {
        this.ruleEnum = ruleEnum;
    }

    public Set<MemberConfigLabelDO> getLabels() {
        return labels;
    }

    public void setLabels(Set<MemberConfigLabelDO> labels) {
        this.labels = labels;
    }

    public Set<RoleDO> getRoles() {
        return roles;
    }

    public void setRoles(Set<RoleDO> roles) {
        this.roles = roles;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MemberConfigDO configDO = (MemberConfigDO) o;
        return Objects.equals(id, configDO.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
